import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { BossRefreshInfo } from "../../../model/BossRefreshInfo";
import { TaskTargetInfo } from "../../../model/TaskTargetInfo";
import { MapFileUtil } from "../../../scene/map/MapFileUtil";
import { EntityType } from "../../../rules/EntityType";
import { AIManager } from "../../../scene/ai/AIManager";
import { Game } from "../../../Game";
import { AIType } from "../../../scene/ai/AIType";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { FlyFootBmp } from "../flyFoot/FlyFootBmp";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { EMapInstanceType } from "../../../../../Message/Public/EMapInstanceType";
//class BossRenderer
    
    export  class BossRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this._npcLabel = new GLabel();
            this._npcLabel.filters = [FilterConst.nameGlowFilter];
            this._npcLabel.width = 150;
            this._npcLabel.height = 20;
            this._npcLabel.mouseChildren = false;
            this._npcLabel.mouseEnabled = true;
            this._npcLabel.buttonMode = true;
            addChild(this._npcLabel);
            this.buttonMode = false;
            this.mouseEnabled = false;
            this.mouseChildren = true;
            this._npcLabel.addEventListener(flash.events.MouseEvent.CLICK, this.onMove, false, 0, true);
            return;
        }

        /* internal  */onMove(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc3=null;
            var loc1=_data as BossRefreshInfo;
            var loc2=loc1.getNormalBoss();
            if (loc2 != null) 
            {
                (loc3 = new TaskTargetInfo()).x = loc1.px;
                loc3.y = loc1.py;
                loc3.id = loc2.code;
                loc3.mapId = MapFileUtil.mapID;
                loc3.targetType = EntityType.Boss;
                AIManager.onAutoPathAIControl(loc3);
            }
            return;
        }

        /* internal  */onFly(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc3=null;
            var loc1=_data as BossRefreshInfo;
            var loc2=loc1.getNormalBoss();
            if (loc2 != null) 
            {
                (loc3 = new TaskTargetInfo()).x = loc1.px;
                loc3.y = loc1.py;
                loc3.id = loc2.code;
                loc3.name = loc2.name;
                loc3.mapId = MapFileUtil.mapID;
                loc3.mapName = Game.sceneInfo.sMapDefine.name;
                loc3.targetType = EntityType.Boss;
                AIManager.onAIControl(loc3, AIType.AI_Convey);
            }
            return;
        }

        /* internal  */updateFlyFoot(): void
        {
            if (!this._flyBitmap) 
            {
                this._flyBitmap = ObjectPool.getObject(FlyFootBmp);
            }
            this._flyBitmap.addEventListener(flash.events.MouseEvent.CLICK, this.onFly, false, 0, true);
            this._flyBitmap.x = this._npcLabel.x + this._npcLabel.textField.textWidth;
            addChild(this._flyBitmap);
            return;
        }

        /* internal  */disposeFlyFoot(): void
        {
            if (this._flyBitmap && this._flyBitmap.parent == this) 
            {
                this._flyBitmap.addEventListener(flash.events.MouseEvent.CLICK, this.onFly, false, 0, true);
                ObjectPool.disposeObject(this._flyBitmap);
                removeChild(this._flyBitmap);
                this._flyBitmap.dispose();
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            var loc1=_data as BossRefreshInfo;
            var loc2=loc1.getNormalBoss();
            this._npcLabel.htmlText = "";
            if (loc1 == null || loc2 == null) 
            {
                this.disposeFlyFoot();
                return;
            }
            this._npcLabel.htmlText = HTMLUtil.addColor(loc2.name, "#ffff00");
            if (Game.sceneInfo.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeCopy) 
            {
                this.disposeFlyFoot();
            }
            else 
            {
                this.updateFlyFoot();
            }
            return;
        }

        public /* override */ get height(): number
        {
            return this._flyBitmap.height;
        }

        protected /* var */_npcLabel: GLabel;

        protected /* var */_flyBitmap: FlyFootBmp;
    }
